package com.study.leetcode;

public class Solution_204 {
    public static int countPrimes(int n) {
        int count = 0;
        boolean[] isPrimes = new boolean[n + 1];
        for (int i = 0; i < n + 1; i++) {
            isPrimes[i] = true;
        }
        //素数筛选法
        for (int i = 2; i < n; i++) {
            if (isPrimes[i]) {
                count++;
                for (int j = 2 * i; j < n; j += i) {
                    isPrimes[j] = false;
                }
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int i = countPrimes(10);
        System.out.println("i = " + i);
    }
}
